#include "CEnemigo.h"
//=============================================================================
CEnemigo::CEnemigo() {
     Type = 	ENTITY_TYPE_ENEMY;
}
//-----------------------------------------------------------------------------
void CEnemigo::OnLoop() {
	CEntity::OnLoop();
}
//-----------------------------------------------------------------------------
void CEnemigo::OnRender(SDL_Surface* Surf_Display) {
	CEntity::OnRender(Surf_Display);
}
//------------------------------------------------------------------------------
void CEnemigo::OnCleanup() {
	CEntity::OnCleanup();
}
//------------------------------------------------------------------------------
void CEnemigo::OnAnimate() {
	if(SpeedX !=0 || SpeedY!=0) {
		Anim_Control.MaxFrames = 6;
	}else{
		Anim_Control.MaxFrames = 0;
	}
	CEntity::OnAnimate();
}
//------------------------------------------------------------------------------
bool CEnemigo::OnCollision(CEntity* Entity) {
//    Jump();
    return true;
}
//------------------------------------------------------------------------------
void CEnemigo::ObtenerDireccion(){
}
//------------------------------------------------------------------------------
void CEnemigo::ObtenerNuevaPosicion(){
    int newX, i=0, newY, posSpawn;
    bool pudeUbicarlo=false,posicionLibre=true,fin=false;
    CMap* Map =CArea::AreaControl.GetMap(1,1);

    while (!pudeUbicarlo){
        posSpawn = rand() % Map->SpawnZList.size() ;
        t_posicion posSpawnJ = Map->SpawnZList.at(posSpawn);
        newX=posSpawnJ.X;
        newY=posSpawnJ.Y;
        i=0;
        fin=false;
        posicionLibre=true;
        while (!fin) {
            if (!this->PosValidObject(ObjectList[i], newX, newY,false)) {
                fin=true;
                posicionLibre=false;
            } else {
                ++i;
                if (i >=ObjectList.size())
                    fin=true;
            }
        }
        if (posicionLibre)
            pudeUbicarlo=true;
    }
    this->X= newX;
    this->Y= newY;
    this->posicionInicial.X=newX;
    this->posicionInicial.Y=newY;
    this->ObtenerDireccion();
}
//=============================================================================
